local FightBuff = class("FightBuff")
local FightConst = require("const.FightConst")

function FightBuff:ctor(config, entity, whoEntity)
    self._config = config
    self._entity = entity
    self._whoEntity = whoEntity
    self._checkCount = 0
    self._attrValue = 0
    self._isRemove = false
end

function FightBuff:addManager(manager)
    self._manager = manager
end

function FightBuff:setElement(element)
    self._element = element
end

function FightBuff:getId()
    return self._config.id
end

function FightBuff:getBuffClass()
    return self._config.class
end

function FightBuff:getConfig()
    return self._config
end

function FightBuff:checkExcute(type, battleReport, ...)
    if self._config.eff_time == type and self:isValid() then
        printDebug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
        printDebug(
            self._entity:getDebugName() ..
                " 执行buff " ..
                    self._config.id ..
                        " 由 " ..
                            self._whoEntity:getDebugName() ..
                                " 上 作用时机 " .. self._config.eff_time .. " 检测时机 " .. self:getCheckType()
        )
        printDebug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
        self:_excute(battleReport, ...)
    end
end

function FightBuff:isValid()
    return (not self._entity:isDie()) and (not self._isRemove)
end

function FightBuff:getEffectTime()
    return self._config.eff_time
end

function FightBuff:_excute(battleReport, ...)
end

function FightBuff:checkOn(battleReport)
    self._checkCount = self._checkCount + 1
    self:checkExcute(FightConst.BUFF_EFF_CHECK, battleReport)
    if self._checkCount >= self._config.chixu_count then
        self:remove(battleReport)
    end
end

function FightBuff:remove(battleReport)
    self:resetbuff(battleReport)
    self._isRemove = true
    self._manager:removeBuff(self, battleReport)
end

function FightBuff:resetbuff()
end

function FightBuff:getCheckType()
    return self._config.check_time
end

function FightBuff:getEntity()
    return self._entity
end

function FightBuff:getWhoEntity()
    return self._whoEntity
end
---
function FightBuff:_attrChange()
    local attack_attr = self._config.attack_attr
    local attack_value = self._config.attack_value
    local isper = self._config.isper
    local toneup = self._config.toneup
    local from = self._config.from
    local dtValue = 0
    if isper then
        local fromValue = 0
        if from > 0 then
            fromValue = self._whoEntity:getAttrValue(from)
        else
            fromValue = self._entity:getAttrValue(attack_attr)
        end
        dtValue = math.floor(fromValue * (attack_value / 1000))
    else
        dtValue = attack_value
    end
    return dtValue
end
---

function FightBuff:checkCondEntity(entity)
    return self._entity:getId() == entity:getId() and (not self._entity:isDie())
end

return FightBuff
